//引入小菠萝仓库
import {defineStore} from "pinia"
//引入接口函数
import { reqGetCategory1ListData,reqGetCategory2ListData,reqGetCategory3ListData } from "@/api/product/category"
//创建模块对象
export const useCategoryListStore = defineStore('categoryList',{
    state:()=>{
        return {
            //接收三级导航ID
            category1ID:undefined || '',
            category2ID:'',
            category3ID:'',
            //接收三级导航数据
            category1ListData:[],
            category2ListData:[],
            category3ListData:[]
        }
    },
    //发送请求更新数据 如果只需直接更新数据，直接更新state就欧克
    actions:{
        //1.获取一级分类数据
        async getCategory1ListData(){
            
            const result = await reqGetCategory1ListData()
            this.category1ListData = result
            console.log("666",this.category1ListData);
        },
        //二级数据列表
        async getCategory2ListData(category1ID:number){
            console.log("[6666]",this);
            
            this.category1ID = category1ID
            const result = await reqGetCategory2ListData(category1ID)
            this.category2ListData = result
            //清空数据
            this.category2ID = undefined
            this.category3ID = undefined
            this.category3List = []

        },
        //获取三级数据
        async reqGetCategory3ListData(category2ID:number){
            this.category2ID = category2ID
            this.category3ListData = await reqGetCategory3ListData(category2ID)
            //重新获取2级id时 3级分类数据为空
            this.category3ID = undefined

        },
        //存储三级ID
        setCategory3ID(val:number){
            this.category3ID = val 
        }

    },
    
})